package com.yyn.Learning.controller;


import com.yyn.Learning.entity.EduChapter;
import com.yyn.Learning.entity.EduVideo;
import com.yyn.Learning.service.EduChapterService;
import com.yyn.Learning.service.EduVideoService;
import com.yyn.R;
import io.swagger.annotations.ApiOperation;
import org.apache.ibatis.annotations.Update;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 课程 前端控制器
 * </p>
 *
 * @author yyn
 * @since 2022-11-22
 */
@RestController
@CrossOrigin
@RequestMapping("/Learning/edu-chapter")
public class EduChapterController {
@Autowired
    EduChapterService eduChapterService;
@ApiOperation("新增篇章")
    @PostMapping("/save")
    public R save(@RequestBody EduChapter eduChapter){
        eduChapterService.saveChapter(eduChapter);
        return R.success().message("新增成功");

    }
    @ApiOperation("删篇章")
    @DeleteMapping("/remove/{id}")
    public R remove(@PathVariable String id) {
        Boolean aBoolean = eduChapterService.removeChapter(id);
        if(aBoolean){
            return R.success().message("删除成功");
        }else{
            return R.error().message("删除失败");

        }

    }
    @ApiOperation("改篇章")
    @PostMapping("/update")
    public R update(@RequestBody EduChapter eduChapter){
        eduChapterService.updateChapter(eduChapter);
        return R.success().message("新增成功");

    }
    @ApiOperation("查篇章")
    @GetMapping("/getAll")
    public R getAll(){
        eduChapterService.getAllChapter();
        return R.success().message("查询成功");

    }
    @ApiOperation("通过id查")
    @GetMapping("/getOne/{id}")
    public R getOne(@PathVariable String id){
        EduChapter eduChapter=eduChapterService.getOneChapter(id);
        return R.success().data("allChapter",eduChapter).message("查询成功");

    }

    @ApiOperation("封装tree显示")
    @GetMapping("/getTree/{id}")
    public R getTree(@PathVariable String id){
        List chapterTree = eduChapterService.getChapterTree(id);
        return R.success().data("chapterTree",chapterTree);
    }
}

